#include "stdafx.h"
#include "Factory.h"
#include "Player.h"

initialiseSingleton(IFactory);
IFactory::IFactory():m_pPlayer(NULL)
{

}

IFactory::~IFactory()
{

}

bool IFactory::Init()
{
    m_pPlayer = NULL;
    cGuidMgr::Init();
    return true;
}

void IFactory::SetPlayerPos()
{
    cGuidMgr::Init();
    CPlayer* pPlayer = GetPlayer();
    if (pPlayer)
    {
        m_posPlayer = pPlayer->GetPos();
    }
}

sPos IFactory::PlayerPos()
{
    return m_posPlayer;
}

void IFactory::Reset()
{
    if (m_pPlayer)
    {
        delete m_pPlayer, m_pPlayer = NULL;
    }

    cGuidMgr::Release();    
}

void IFactory::Stop()
{
    if (m_pPlayer)
    {
        delete m_pPlayer, m_pPlayer = NULL;
    }
    cGuidMgr::Release();     
}

void IFactory::Run()
{
    if (cGuidMgr::getSingletonPtr()==NULL)
    {
        return;
    }

    cGuidMgr::getSingleton().GetGuids(m_listGuids, 0);
}

CPlayer* IFactory::GetPlayer()
{
    sGuid guid = cGuidMgr::getSingleton().PlayerGuid();
    if (m_pPlayer)
    {
        m_pPlayer->Update(guid);
    }
    else
    {
        m_pPlayer = new CPlayer();
        m_pPlayer->Update(guid);
    }
    return m_pPlayer;
}
